pub fn min_edge_prime_num(threshold: u32) -> String {
    let mut primes = 0;
    let mut total = 1;
    let mut number = 1u64;
    let mut edge_length = 1;

    while edge_length == 1 || (primes * 100) / (total as u32) >= threshold {
        edge_length += 2;
        for _ in 0..4 {
            number += edge_length as u64 - 1;
            if is_prime(number) {
                primes += 1;
            }
        }
        total += 4;
    }

    format!("{},{}", edge_length, primes)
}

// Modular multiplication to prevent overflow
fn modular_mul(a: u64, b: u64, modulus: u64) -> u64 {
    let result = (a as u128 * b as u128) % modulus as u128;
    result as u64
}

// Modular exponentiation using square-and-multiply
fn modular_pow(mut base: u64, mut exponent: u64, modulus: u64) -> u64 {
    let mut result = 1u64;
    base %= modulus;
    while exponent > 0 {
        if exponent % 2 == 1 {
            result = modular_mul(result, base, modulus);
        }
        base = modular_mul(base, base, modulus);
        exponent /= 2;
    }
    result
}

const SMALL_PRIMES: [u64; 12] = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37];

fn is_prime(n: u64) -> bool {
    if n < 2 {
        return false;
    }
    if n < 40 {
        return SMALL_PRIMES.contains(&n);
    }
    for &a in &SMALL_PRIMES {
        if !miller_rabin_test(n, a) {
            return false;
        }
    }
    true
}

fn miller_rabin_test(n: u64, a: u64) -> bool {
    let mut d = n - 1;
    while d % 2 == 0 {
        d /= 2;
    }
    let mut x = modular_pow(a, d, n);
    if x == 1 || x == n - 1 {
        return true;
    }
    while d != n - 1 {
        x = modular_mul(x, x, n);
        d *= 2;
        if x == 1 {
            return false;
        }
        if x == n - 1 {
            return true;
        }
    }
    false
}